<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/limh/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/limh/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/limh/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/limh/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/limh/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/limh/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/limh/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="教程,">










<meta name="description" content="库文件对学过C/C++语言程序设计的读者来说应该是不会陌生的，该语言的程序设计环境提供了大量的库文件，也就是说，提供了大量的标准函数或过程。在本节里，介绍读者如何创建自己的库文件。  7.6.1 建立库文件命令LIB宏汇编MASM系统提供了建立库文件的命令文件LIB.EXE。其通常是在命令行环境(MS-DOS方式)下使用的，当然，也可在Windows 95/98等环境下利用其“开始”菜单下的“运行">
<meta name="keywords" content="教程">
<meta property="og:type" content="article">
<meta property="og:title" content="7.6 子程序库">
<meta property="og:url" content="https://tdnr.gitee.io/limh/2015/04/01/asm33/index.html">
<meta property="og:site_name" content="土逗牛肉">
<meta property="og:description" content="库文件对学过C/C++语言程序设计的读者来说应该是不会陌生的，该语言的程序设计环境提供了大量的库文件，也就是说，提供了大量的标准函数或过程。在本节里，介绍读者如何创建自己的库文件。  7.6.1 建立库文件命令LIB宏汇编MASM系统提供了建立库文件的命令文件LIB.EXE。其通常是在命令行环境(MS-DOS方式)下使用的，当然，也可在Windows 95/98等环境下利用其“开始”菜单下的“运行">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image001_0103.gif">
<meta property="og:image" content="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image002_0039.gif">
<meta property="og:updated_time" content="2019-01-21T13:59:48.423Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="7.6 子程序库">
<meta name="twitter:description" content="库文件对学过C/C++语言程序设计的读者来说应该是不会陌生的，该语言的程序设计环境提供了大量的库文件，也就是说，提供了大量的标准函数或过程。在本节里，介绍读者如何创建自己的库文件。  7.6.1 建立库文件命令LIB宏汇编MASM系统提供了建立库文件的命令文件LIB.EXE。其通常是在命令行环境(MS-DOS方式)下使用的，当然，也可在Windows 95/98等环境下利用其“开始”菜单下的“运行">
<meta name="twitter:image" content="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image001_0103.gif">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/limh/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tdnr.gitee.io/limh/2015/04/01/asm33/">





  <title>7.6 子程序库 | 土逗牛肉</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans ">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/limh/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">土逗牛肉</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/limh/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/limh/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/limh/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/limh/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/limh/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tdnr.gitee.io/limh/limh/2015/04/01/asm33/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="土逗牛肉">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/limh/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="土逗牛肉">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">7.6 子程序库</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-04-01T20:35:58+08:00">
                2015-04-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/limh/categories/汇编教程/" itemprop="url" rel="index">
                    <span itemprop="name">汇编教程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>库文件对学过C/C++语言程序设计的读者来说应该是不会陌生的，该语言的程序设计环境提供了大量的库文件，也就是说，提供了大量的标准函数或过程。在本节里，介绍读者如何创建自己的库文件。</p>
<hr>
<h2 id="7-6-1-建立库文件命令LIB"><a href="#7-6-1-建立库文件命令LIB" class="headerlink" title="7.6.1 建立库文件命令LIB"></a>7.6.1 建立库文件命令LIB</h2><p>宏汇编MASM系统提供了建立库文件的命令文件LIB.EXE。其通常是在命令行环境(MS-DOS方式)下使用的，当然，也可在Windows 95/98等环境下利用其“开始”菜单下的“运行”功能项来使用。</p>
<h3 id="一、MS-DOS系统"><a href="#一、MS-DOS系统" class="headerlink" title="一、MS-DOS系统"></a>一、MS-DOS系统</h3><p>显示命令LIB用法的命令如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">…&gt;lib /?</span><br></pre></td></tr></table></figure>
<p>该命令的显示结果如图7.9中所示。</p>
<h3 id="二、Windows系统"><a href="#二、Windows系统" class="headerlink" title="二、Windows系统"></a>二、Windows系统</h3><p><img src="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image001_0103.gif" alt="图7.8 运行LIB命令的画面"></p>
<center><strong>图7.8 运行LIB命令的画面</strong></center>

<p><img src="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image002_0039.gif" alt="图7.9 显示LIB命令功能的画面"></p>
<center><strong>图7.9 显示LIB命令功能的画面</strong></center>

<p>命令LIB的使用方式和显示结果如图7.8和7.9所示。</p>
<h3 id="三、命令显示内容的解释"><a href="#三、命令显示内容的解释" class="headerlink" title="三、命令显示内容的解释"></a>三、命令显示内容的解释</h3><p><strong>1)、各选项的解释</strong></p>
<table border="0" cellspacing="3" cellpadding="0"><tr> <td> 选项 </td><td colspan="2"><p>含义 </p></td></tr><tr><td>/?、/HELP</td><td colspan="2"><p>显示LIB命令的用法，描述各命令行参数的含义 </p></td></tr><tr><td>/IGNORECASE</td><td>忽略子程序名中的大小写 </td><td rowspan="2"><p>在实践中，作用不明显 </p></td></tr><tr><td>/NOIGNORECASE</td><td>不忽略子程序名中的大小写 </td></tr><tr><td>/NOEXTDICTIONARY</td><td colspan="2"><p>不建立扩展的目录 </p></td></tr><tr><td>/NOLOGO</td><td colspan="2"><p>不显示版本号和版权信息 </p></td></tr><tr><td>/PAGESIZE:n</td><td colspan="2"><p>设置库文件的每页字节数为n</p></td></tr></table>

<p><strong>2)、命令项的解释：</strong></p>
<table border="0" cellspacing="3" cellpadding="0"><tr><td> 选项 </td><td>含义 </td></tr><tr><td>+name</td><td>向库文件中加一个新的目标文件 </td></tr><tr><td>-name</td><td>从库文件中删除一个指定的目标文件 </td></tr><tr><td>-+name</td><td>用新的目标文件替换掉库文件中原有的目标文件 </td></tr><tr><td><em>name</em></td><td>拷贝出指定的目标文件 </td></tr><tr><td>-name</td><td>从库文件中移出指定的目标文件 </td></tr></table>

<p>在弄懂了LIB的各项功能含义后，读者就可根据自己的需要来建立库文件了。</p>
<h2 id="7-6-3-库文件的应用"><a href="#7-6-3-库文件的应用" class="headerlink" title="7.6.3 库文件的应用"></a>7.6.3 库文件的应用</h2><p>在开发一个功能较弱的应用程序时，其执行文件通常可由一个目标文件连接而成，当开发一个功能较强、关系较复杂的应用程序时，其执行文件很难由一个目标文件连接而成，常常是由多个目标文件(模块)连接而成的。各模块之间无疑会存在着相互调用、相互访问数据单元等内在联系，各模块之间的相互联系就产生了这样的问题：程序员如何在源程序中来表达这种联系？</p>
<p>为了解决描述各模块之间的联系，汇编语言提供了二条伪指令PUBLIC和EXTRN，它们的作用有点象C/C++语言说明变量、过程和函数是“全局的”或“外部的”。</p>
<p>这二条伪指令的具体用法和含义如下：</p>
<h3 id="1、伪指令PUBLIC"><a href="#1、伪指令PUBLIC" class="headerlink" title="1、伪指令PUBLIC"></a>1、伪指令PUBLIC</h3><p>伪指令PUBLIC是用来说明：当前模块中哪些标识符是能被其它模块引用的公共标识符。其说明的一般格式如下：</p>
<p>PUBLIC　标识符1, 标识符2, ……</p>
<p>其中：“标识符”可以是变量名、过程名和程序标号，各标识符之间要用逗号分开。</p>
<p>上面说明语句说明了标识符1、标识符2等是公共标识符，可以被其它模块引用。在一个模块中，可用多条PUBLIC伪指令来说明公共标识符。</p>
<h3 id="2、伪指令EXTRN"><a href="#2、伪指令EXTRN" class="headerlink" title="2、伪指令EXTRN"></a>2、伪指令EXTRN</h3><p>伪指令EXTRN是用来说明：在当前模块所使用的标识符中，哪些标识符是已在其它模块中被定义为指定类型的标识符。如果当前模块使用了其它模块的标识符，而对它又不加以说明的话，那么，在汇编时，汇编程序将会给出下列出错信息：</p>
<p>error nnnnn: undefined symbol : XXXXXX</p>
<p>其中：“nnnnn”是错误号，“XXXXXX”是当前模块中没有定义的标识符。</p>
<p>伪指令EXTRN的一般说明格式如下：</p>
<p>EXTRN　标识符1:类型1, 标识符2:类型2, ……</p>
<p>其中：“标识符”和“类型”之间要用冒号“:”连接。</p>
<p>上面语句说明了标识符1、标识符2等是外部标识符，它们在其它模块中已被分别定义为类型1、类型2等，该类型说明符可以是：NEAR、FAR、BYTE、WORD、DWORD等之一。如果在一条说明伪指令中说明了多个标识符，那么，各标识符之间要用逗号分开。</p>
<p>在一个模块中，可用多条EXTRN伪指令来说明本模块所引用的外部标识符。</p>
<p>注意：伪指令EXTRN中所说明的标识符必须在其定义的模块中被PUBLIC伪指令说明为公共标识符，并且其说明的标识符类型要与该标识符在定义是的类型相一致，否则，要么不能生成其可执行文件，要么其执行文件不能正确运行。</p>
<p>例7.7 把例7.3、7.4和7.5合并在一起生成一个可执行文件，假设它们所对应的源程序名分别为Count.ASM、DispBX.ASM和Main.ASM。</p>
<p>解：由于在源文件Count.ASM中调用了子程序UPPER，所以，例7.1的程序也必须加入到本题中。假设其源文件名为Upper.ASM。</p>
<p>由于生成本题的执行文件需要四个模块，模块之间存在着调用关系，所以，在有关源文件中需要说明某些标识符为外部属性，或说明其为公共属性。</p>
<p>为了把前面例子中的子程序改写成可汇编的程序，需要添加一些简单的说明语句或进行简单修改，其添加或改写的部分已在下面用“下划线”表示出来。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line">;源文件Upper.ASM</span><br><span class="line"></span><br><span class="line">;子程序说明信息：……</span><br><span class="line"></span><br><span class="line">PUBLIC UPPER</span><br><span class="line"></span><br><span class="line">SegUpr SEGMENT &apos;code&apos;</span><br><span class="line"></span><br><span class="line">UPPER PROC　FAR </span><br><span class="line"></span><br><span class="line">…… ;例7.1中的程序段，在此从略 </span><br><span class="line"></span><br><span class="line">UPPER ENDP</span><br><span class="line"></span><br><span class="line">SegUpr ENDS</span><br><span class="line"></span><br><span class="line">END</span><br><span class="line"></span><br><span class="line">;源文件DispBX.ASM</span><br><span class="line"></span><br><span class="line">;子程序说明信息：……</span><br><span class="line"></span><br><span class="line">PUBLIC DISPBX</span><br><span class="line"></span><br><span class="line">SubData? SEGMENT</span><br><span class="line"></span><br><span class="line">DB 5 DUP(&apos;0&apos;), 0ah, 0dh, &apos;$&apos;</span><br><span class="line"></span><br><span class="line">SubData? ENDS</span><br><span class="line"></span><br><span class="line">SegDisp? SEGMENT?&apos;code&apos;</span><br><span class="line"></span><br><span class="line">DISPBX PROC?FAR</span><br><span class="line"></span><br><span class="line">…… ;例7.3中的程序段，在此从略 </span><br><span class="line"></span><br><span class="line">DISPBX ENDP</span><br><span class="line"></span><br><span class="line">SegDisp? ENDS</span><br><span class="line"></span><br><span class="line">END</span><br><span class="line"></span><br><span class="line">;源文件Count.ASM</span><br><span class="line"></span><br><span class="line">;子程序说明信息：……</span><br><span class="line"></span><br><span class="line">PUBLIC COUNT</span><br><span class="line"></span><br><span class="line">EXTRN UPPER:FAR</span><br><span class="line"></span><br><span class="line">SegCount SEGMENT?&apos;code&apos;</span><br><span class="line"></span><br><span class="line">COUNT PROC?FAR</span><br><span class="line"></span><br><span class="line">…… ;例7.4中的程序段，在此从略 </span><br><span class="line"></span><br><span class="line">COUNT ENDP</span><br><span class="line"></span><br><span class="line">SegCount ENDS</span><br><span class="line"></span><br><span class="line">END</span><br><span class="line"></span><br><span class="line">;源文件Main.ASM</span><br><span class="line"></span><br><span class="line">EXTRN COUNT:FAR, DISPBX:FAR</span><br><span class="line"></span><br><span class="line">.MODEL? SMALL</span><br><span class="line"></span><br><span class="line">.DATA</span><br><span class="line"></span><br><span class="line">STR? DB　&apos;KSDJ L0984/[]3oiu OIU OIU (*&amp;(5341&apos;, 0</span><br><span class="line"></span><br><span class="line">.CODE</span><br><span class="line"></span><br><span class="line">.STARTUP</span><br><span class="line"></span><br><span class="line">LEA? DX, STR</span><br><span class="line"></span><br><span class="line">CALL COUNT ;调用子程序统计出各类字符的个数 </span><br><span class="line"></span><br><span class="line">CALL DISPBX ;调用子程序显示数字字符的个数 </span><br><span class="line"></span><br><span class="line">MOV BX, CX</span><br><span class="line"></span><br><span class="line">CALL DISPBX ;调用子程序显示字母的个数 </span><br><span class="line"></span><br><span class="line">MOV BX, DI</span><br><span class="line"></span><br><span class="line">CALL DISPBX ;调用子程序显示其它字符的个数 </span><br><span class="line"></span><br><span class="line">.EXIT 0</span><br><span class="line"></span><br><span class="line">END</span><br></pre></td></tr></table></figure>
<p>经过以上改写后，可用下列命令把它们分别汇编成目标文件(假设已安装了MASM编程环境)：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">…&gt;MASM?upper</span><br><span class="line"></span><br><span class="line">…&gt;MASM?dispbx</span><br><span class="line"></span><br><span class="line">…&gt;MASM?count</span><br><span class="line"></span><br><span class="line">…&gt;MASM?main</span><br></pre></td></tr></table></figure>
<p>有了这些目标文件后，可用以下二种方法来生成可执行文件。</p>
<p><strong>方法1：把所有的目标文件连接在一起</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">…&gt;link  main+upper+count+dispbx</span><br></pre></td></tr></table></figure>
<p><strong>方法2：把目标文件upper.obj、count.obj和dispbx.obj加到自己开发的库文件中，然后在连接时，与该库文件连接。</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">…&gt;lib?mylib +upper +count +dispbx</span><br><span class="line"></span><br><span class="line">…&gt;link?main</span><br><span class="line"></span><br><span class="line">Microsoft (R) Segmented Executable Linker?Version 5.31.009 Jul 13 1992</span><br><span class="line"></span><br><span class="line">Copyright (C) Microsoft Corp 1984-1992.?All rights reserved.</span><br><span class="line"></span><br><span class="line">Run File [main.exe]:</span><br><span class="line"></span><br><span class="line">List File [nul.map]:</span><br><span class="line"></span><br><span class="line">Libraries [.lib]: mylib　;输入要连接的库文件，可用加号“+”连接多个库文件 </span><br><span class="line"></span><br><span class="line">Definitions File [nul.def]:</span><br><span class="line"></span><br><span class="line">LINK : warning L4021: no stack segment</span><br><span class="line"></span><br><span class="line">…&gt;main　;运行生成的文件</span><br></pre></td></tr></table></figure>
<p>以上各步骤也可由集成开发环境PWB来完成，具体介绍请见附录1。另外，当模块的指令条数较少时，也可以把几个子模块合在一个源文件中。</p>
<p>##7.6.4 库文件的好处</p>
<p>程序员在编写源程序时，通常采用模块化的思想来组织源程序：把各类不同的子程序分别编写在不同的源程序中，在各源程序中说明所用到的在其它模块中定义，或说明本模块的定义子程序可被其它模块调用。这样组织后，就可以分别汇编它们而得到其相应的目标文件，在有了这些目标文件后，就可生成最终的可执行文件，但可用不同的方法来生成最终的可执行目标文件。</p>
<p><strong>方法1：直接连接目标文件而生成可执行文件(如上节例7.6中的方法1所示)</strong></p>
<p>这种方法简单、方便，也是常用的一种方法，但在连接时，LINK程序会把目标文件中的所有代码都嵌入到执行文件中，从而使得：包含在某目标文件中、但并没有被调用的子程序代码也出现在执行文件中。这种情况无疑增加了执行文件的字节数。</p>
<p><strong>方法2：采用子程序库的方法(如上节例7.6中的方法2所示)</strong></p>
<p>库文件可以把它看成是子程序的集合。库文件中存储着子程序名、子程序的目标代码以及连接所需要的重定位信息。当某目标文件与库文件相连接时，LINK程序只把目标文件所用到的子程序从库文件中找出来，并合并到最终的可执行文件中，而不是把库中所含的全部子程序都纳入最后的可执行文件。</p>
<p>对照方法1和2可知：用库文件来存储子程序可生成较短的执行文件。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/limh/tags/教程/" rel="tag"># 教程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/limh/2015/04/01/asm32/" rel="next" title="7.5 子程序的完全定义">
                <i class="fa fa-chevron-left"></i> 7.5 子程序的完全定义
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/limh/2015/04/01/asm34/" rel="prev" title="8.1 输入输出的基本概念">
                8.1 输入输出的基本概念 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/limh/images/avatar.jpg" alt="土逗牛肉">
            
              <p class="site-author-name" itemprop="name">土逗牛肉</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/limh/archives/">
              
                  <span class="site-state-item-count">255</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/limh/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/limh/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/limhGeek" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:1591054297@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/f73b243e7cc9" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-user-circle-o"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#7-6-1-建立库文件命令LIB"><span class="nav-number">1.</span> <span class="nav-text">7.6.1 建立库文件命令LIB</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#一、MS-DOS系统"><span class="nav-number">1.1.</span> <span class="nav-text">一、MS-DOS系统</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#二、Windows系统"><span class="nav-number">1.2.</span> <span class="nav-text">二、Windows系统</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#三、命令显示内容的解释"><span class="nav-number">1.3.</span> <span class="nav-text">三、命令显示内容的解释</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-6-3-库文件的应用"><span class="nav-number">2.</span> <span class="nav-text">7.6.3 库文件的应用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、伪指令PUBLIC"><span class="nav-number">2.1.</span> <span class="nav-text">1、伪指令PUBLIC</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、伪指令EXTRN"><span class="nav-number">2.2.</span> <span class="nav-text">2、伪指令EXTRN</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">土逗牛肉</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
	var str = GetUrlParam('height');
    if (str === '0'){
		document.getElementById('header').style.display = 'none';
		document.getElementById('comments').style.display = 'none';
		document.getElementById('footer').style.display = 'none';
		document.getElementsByClassName('post-footer').item(0).style.display = 'none'
	}
	
    function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                 arr = arrPara[i].split("=");

                if (arr != null && arr[0] === paraName) {
                    return arr[1];
                }
            }
            return "";
        } else {
            return "";
        }
    }
</script>









  












  
  
    <script type="text/javascript" src="/limh/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/limh/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/limh/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/limh/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/limh/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/limh/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
